package com.hainatong.shiphelper.mainhome;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageButton;
import android.widget.TextView;
import androidx.appcompat.widget.Toolbar;
import com.blankj.utilcode.util.ObjectUtils;
import com.blankj.utilcode.util.StringUtils;
import com.hainatong.shiphelper.R;
import com.hainatong.shiphelper.databinding.ActivityYanxiBinding;
import com.hainatong.shiphelper.utils.GsonUtil;
import com.hainatong.mvvmbase.base.BaseMvvmActivity;
import com.hainatong.mvvmbase.base.NoViewModel;

public class YanxiActivity extends BaseMvvmActivity<ActivityYanxiBinding, NoViewModel>
{
    public static String YANXI_TAG = "YanxiActivity";

    private String yanxiBean;

    public static void startByParam(Activity mContext, String yanxiInfo )
    {
        Bundle bundle = new Bundle();
        bundle.putString(YANXI_TAG, GsonUtil.obj2json( yanxiInfo ));
        start(mContext, bundle, false);
    }

    public static void start(Activity mContext, Bundle bundle)
    {
        start(mContext, bundle, false);
    }

    public static void start(Activity mContext, Bundle bundle, boolean isFinish)
    {
        Intent intent = new Intent();
        intent.setClass(mContext, YanxiActivity.class);
        if (bundle != null) intent.putExtra(mContext.getPackageName(), bundle);
        mContext.startActivity(intent);
        if (isFinish)
        {
            mContext.finish();
        }
    }


    @Override
    protected int getLayoutId()
    {
        return R.layout.activity_yanxi;
    }

    @Override
    protected int getBindingVariable() {
        return 0;
    }

    public Bundle getBundle()
    {
        if (getIntent() != null && getIntent().hasExtra(getPackageName()))
            return getIntent().getBundleExtra(getPackageName());
        else
            return null;
    }

    @Override
    protected void initView()
    {

        Bundle bundle = getBundle();
        if(ObjectUtils.isNotEmpty( bundle ))
        {
            String infoStr = bundle.getString(YANXI_TAG ,"");
            if(!StringUtils.isEmpty( infoStr ))
            {
                yanxiBean = GsonUtil.json2Obj( infoStr , String.class );
            }
        }

        setToolbarTitle(viewDataBinding.includeTitle.toolbar,getString(R.string.detail));

    }

    @Override
    protected void initData()
    {
    }

    @Override
    protected void onRetryBtnClick()
    {
    }

    private void setToolbarTitle(Toolbar toolbar, String title) {
        // toolbar.setBackgroundColor(ContextCompat.getColor(this,R.color.red));

        ((TextView) toolbar.findViewById(R.id.tv_title)).setText(title);
        ((ImageButton) toolbar.findViewById(R.id.btn_back)).setImageResource(R.drawable.svg_back);
        toolbar.findViewById(R.id.btn_back).setOnClickListener(v -> {
            supportFinishAfterTransition();
        });
    }

}
